package com.lagou.search.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * Swagger配置文件
 * @author yzh
 * @since 2021/12/3
 **/
@Configuration
@EnableSwagger2
public class SwaggerConfiguration {

    @Bean(value = "swaggerApi")
    public Docket swaggerApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                //分组名称
                .groupName("v1.0")
                .select()
                //这里指定Controller扫描包路径
                .apis(RequestHandlerSelectors.basePackage("com.lagou.search.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    /**
     * 封装API信息
     * @return API信息
     */
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("lagou search")
                .description("lagou search RESTful APIs")
                .termsOfServiceUrl("http://www.lagou.com/")
                .version("1.0")
                .build();
    }

}